package com.cloud.cmt.usermanage.controller;

import com.angela.cloud.common.base.ResultMessage;
import com.cloud.cmt.usermanage.entity.vo.EnterpriseDetailVO;
import com.cloud.cmt.usermanage.entity.vo.RegistrationVO;
import com.cloud.cmt.usermanage.service.EnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 浙江卓锐科技股份有限公司 版权所有 © Copyright 2017<br>
 * 说明: 企业详情操作<br>
 * 项目名称: cloud-maintenance <br>
 * 创建日期: 2017年10月21日 15:49 <br>
 * 作者: <a href="6492178@gmail.com">汪萌萌</a>
 */
@RestController
@RequestMapping("/enterprise")
@Api(tags = "enterprise", description = "企业详情相关操作-by汪萌萌")
public class EnterpriseCtl {
    @Resource
    private EnterpriseService enterpriseService;

    @PostMapping("/uploadPic")
    @ApiOperation(value = "上传营业执照")
    public ResultMessage upLoadPic(@RequestParam(value = "file)") MultipartFile file) {
        return enterpriseService.upLoadPic(file);
    }

    @GetMapping("/getSmsVerificationCode/{phone}")
    @ApiOperation(value = "获取验证码")
    public ResultMessage getSmsVerificationCode(HttpServletRequest request, @PathVariable String phone) {
        return enterpriseService.getSmsVerificationCode(request, phone);
    }

    @GetMapping("/checkUsername/{username}")
    @ApiOperation(value = "检查企业账户用户名是否可用")
    public ResultMessage checkUsername(@PathVariable @ApiParam(value = "待检测用户名") String username) {
        return enterpriseService.checkUsername(username);
    }

    @GetMapping("/checkSocialCreditCode/{social_credit_code}")
    @ApiOperation(value = "检查企业营业执照是否唯一")
    public ResultMessage checkSocialCreditCode(@PathVariable(name = "social_credit_code") @ApiParam(name = "social_credit_code", value = "待检测营业执照编号") String socialCreditCode) {
        return enterpriseService.checkSocialCreditCode(socialCreditCode);
    }

    @PostMapping("/applyForProbation/{code}")
    @ApiOperation(value = "申请试用", notes = "申请使用前需校验用户名和营业执照是否唯一")
    public ResultMessage applyForProbation(@RequestBody @Validated RegistrationVO registrationVO, @ApiParam(value = "短信验证码") @PathVariable Integer code) {
        return enterpriseService.applyForProbation(registrationVO.getDetail(), registrationVO.getUser(), registrationVO.getReferrer(), code);
    }

    @PostMapping("/reApplyForProbation")
    @ApiOperation(value = "重新申请试用")
    public ResultMessage reApplyForProbation(@RequestBody @Validated EnterpriseDetailVO enterpriseDetailVO) {
        return enterpriseService.reApplyForProbation(enterpriseDetailVO);
    }

}
